package model;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

public class Term {
	private String name;
	private int frequence;
	private double chisq;
	private HashMap<String, Document> documents;
	
	public Term(String name) {
		this.name = name;
		this.frequence = 0;
		this.documents = new HashMap<String, Document>();
	}

	public int getFrequence() {
		return frequence;
	}

	public void setFrequence(int frequence) {
		this.frequence = frequence;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public HashMap<String, Document> getDocuments() {
		return documents;
	}

	public void setDocuments(HashMap<String, Document> documents) {
		this.documents = documents;
	}
	
	public void addDocument(Document doc) {
		String id = Integer.toString(doc.getId());
		if(doc != null && !this.documents.containsKey(id))
			this.documents.put(id, doc);
	}
	
	public void incFreq() {
		this.frequence++;
	}

	public double getChisq() {
		return chisq;
	}

	public void setChisq(double chisq) {
		this.chisq = chisq;
	}
	
	public void removeFromDocuments() {
		Collection<Document> col = documents.values();
		
		for (Document doc:col){
			doc.removeTerm(name);
		}
	}
}
